package system.runner;

import framework.config.ServerConfig;
import framework.config.ServletConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.stereotype.Component;
import springfox.documentation.spring.web.plugins.Docket;

@Slf4j
@Component
@ConditionalOnWebApplication
public class ServerEnvPrintRunner implements CommandLineRunner {
    @Autowired
    private ServerConfig serverConfig;
    @Autowired
    private ServletConfig servletConfig;
    @Autowired
    private Docket docket;

    @Override
    public void run(String... args) throws Exception {
        String address = "http://127.0.0.1:" + serverConfig.getPort();
        if (StringUtils.isNotBlank(servletConfig.getContextPath())) {
            address += servletConfig.getContextPath();
        }
        log.info("Listen: {}", address);
        if (docket.isEnabled()) {
            log.info("Swagger: {}", address + "/swagger-ui/");
        }
    }
}
